package com.cloud.spring.demo.controller;

import com.cloud.spring.demo.entity.User;
import com.cloud.spring.demo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Optional;

@RestController
@RequestMapping("es")
public class UserController {
    @Autowired
    UserService userService;

    @GetMapping("save")
    public User save() {
        User user = new User();
        user.setId(2);
        user.setName("tina");
        return userService.save(user);
    }

    @GetMapping("findById")
    public Optional<User> findById(int id) {
        return userService.findById(id);
    }

    @GetMapping("findAll")
    public Iterable<User> findAll() {
        return userService.findAll();
    }

    @GetMapping("findPageByName")
    public Page<User> findByName(String name, Pageable pageable) {
        return userService.findPageByName(name, pageable);
    }

    @GetMapping("findByFilterBuilder")
    public Page<User> findByFilterBuilder() {
        return userService.findByFilterBuilder();
    }

    @GetMapping("findBigResultByScanAndScroll")
    public Page<User> findBigResultByScanAndScroll() {
        return userService.findBigResultByScanAndScroll();
    }
}
